package com.jiangyg.devtools.toolkit;

import com.intellij.notification.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.geom.AffineTransform;

/**
 * 类描述：工具包
 *
 * @author jiangyg
 * @version 1.0
 * @date 2023年08月14日
 */
public class AwtUtils {

    private static final NotificationGroupManager notificationGroupManager;

    private static final NotificationGroup balloonNotificationGroup;

    static {
        notificationGroupManager = NotificationGroupManager.getInstance();
        balloonNotificationGroup = notificationGroupManager.getNotificationGroup("com.jiangyg.devtools");
    }

    /**
     * 功能描述：错误提示
     *
     * @param message 消息内容
     */
    public static void successTip(String message) {
        Messages.showInfoMessage(message, "操作提示");
    }

    /**
     * 功能描述：错误提示
     *
     * @param message 消息内容
     */
    public static void errorTip(String message) {
        Messages.showErrorDialog(message, "错误提示");
    }

    /**
     * 功能描述：自动消失的右下角提示框
     *
     * @param message 消息内容
     * @param type    消息类型
     */
    public static void balloonTip(String message, NotificationType type) {
        final Notification notification = balloonNotificationGroup.createNotification(message, type);
        Notifications.Bus.notify(notification);
    }

    /**
     * 功能描述：自动消失的右下角提示框
     *
     * @param message 消息内容
     * @param type    消息类型
     * @param project 项目
     */
    public static void balloonTip(String message, NotificationType type, Project project) {
        final Notification notification = balloonNotificationGroup.createNotification(message, type);
        notification.notify(project);
    }

    /**
     * 功能描述：设置剪切板字符串内容
     *
     * @param str 内容
     */
    public static void setClipboardContents(String str) {
        final StringSelection selection = new StringSelection(str);
        final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(selection, selection);
        balloonTip("已复制到剪切板", NotificationType.INFORMATION);
    }

    /**
     * 功能描述：获取显示器尺寸
     *
     * @return 显示器尺寸
     */
    public static Dimension getScreenSize() {
        final Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
        return defaultToolkit.getScreenSize();
    }

    /**
     * 功能描述：获取显示器分辨率
     *
     * @return 显示器分辨率
     */
    public static DisplayMode getScreenDPI() {
        final GraphicsDevice graphDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        return graphDevice.getDisplayMode();
    }

    /**
     * 功能描述：获取显示器分辨率缩放比例
     *
     * @return 显示器分辨率缩放比例
     */
    public static AffineTransform getScreenTransform() {
        final GraphicsConfiguration gc = GraphicsEnvironment
                .getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().
                getDefaultConfiguration();
        return gc.getDefaultTransform();
    }

}
